namespace SimpleWebServices.Web.UI.Html.Elements
{
    using System.Xml.Serialization;
    using SimpleWebServices;
    using Xunit;

    public sealed class SubmitButtonFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<SubmitButton>()
                .DerivesFrom<Button>()
                .IsConcreteClass()
                .IsSealed()
                .HasDefaultConstructor()
                .Implements<IXmlSerializable>()
                .XmlRoot("button")
                .Result);
        }

        [Fact]
        public void deserialize()
        {
            SubmitButton expected = new SubmitButton(new Name("id"))
            {
                Class = "class",
                Accesskey = 'a',
                Disabled = true,
                Language = "fr",
                TabIndex = 1,
                Title = "title",
                Value = "value"
            };

            string xml = "<button id='id' class='class' lang='fr' title='title' name='id' accesskey='a' tabindex='1' disabled='disabled' type='submit' value='value' />";
            SubmitButton actual = xml.Deserialize<SubmitButton>();

            Assert.Equal<string>(expected.ToString(), actual.ToString());
        }

        [Fact]
        public void deserializeEmpty()
        {
            Assert.NotNull("<button type='submit' />".Deserialize<SubmitButton>());
        }

        [Fact]
        public void serialize()
        {
            SubmitButton obj = new SubmitButton(new Name("id"))
            {
                Class = "class",
                Accesskey = 'a',
                Disabled = true,
                Language = "fr",
                TabIndex = 1,
                Title = "title",
                Value = "value"
            };

            string xpath = "1=count(/button[@id='id'][@class='class'][@lang='fr'][@title='title'][@tabindex='1'][@disabled='disabled'][@accesskey='a'][@type='submit'][@value='value'])";

            Assert.True((bool)obj.Serialize().CreateNavigator().Evaluate(xpath));
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new SubmitButton());
        }

        [Fact]
        public void ctor_Name()
        {
            Assert.NotNull(new SubmitButton(new Name("id")));
        }

        [Fact]
        public void ctor_NameNull()
        {
            Assert.NotNull(new SubmitButton(null));
        }

        [Fact]
        public void prop_Type()
        {
            Assert.True(new PropertyExpectations(typeof(SubmitButton).GetProperty("Type"))
                .DefaultValueIs("submit")
                .Result);
        }

        [Fact]
        public void op_Deserialize_string_string_string()
        {
            SubmitButton expected = new SubmitButton(new Name("id"))
            {
                Class = "class",
                Accesskey = 'a',
                Disabled = true,
                Language = "fr",
                TabIndex = 1,
                Title = "title",
                Value = "value"
            };

            string xml = "<button id='id' class='class' lang='fr' title='title' name='id' accesskey='a' tabindex='1' disabled='disabled' type='submit' value='value' />";
            SubmitButton actual = new SubmitButton().Deserialize("button", "submit", xml) as SubmitButton;

            Assert.Equal<string>(expected.ToString(), actual.ToString());
        }
    }
}